import dayjs from 'dayjs';
import { create } from 'zustand';
import moment from 'moment';

export type TabItem = {
	label: string | React.ReactNode;
	key: string;
	index: number;
	isOther: boolean;
};

export const MonthYearTabs = [
	{
		label: '月累计',
		value: '1'
	},
	{
		label: '年累计',
		value: '2'
	}
] as const;

export type MonthYearKey = (typeof MonthYearTabs)[number]['value'];

export type ServiceTypeItem = {
	label: string;
	value: string;
};

export type SaleTabStore = {
	active: TabItem | null;
	setActive(t: TabItem): void;
	serviceType: ServiceTypeItem;
	setServiceType(type: ServiceTypeItem): void;
	currentDate: number;
	setCurrentDate(v: number): void;
	monthOrYear: MonthYearKey;
	setMonthOrYear(v: MonthYearKey): void;
};

export const useSaleTabStore = create<SaleTabStore>(set => {
	return {
		active: null,
		serviceType: '',
		currentDate: dayjs().subtract(1, 'day').valueOf(),
		scope: 1,
		setActive(tab: TabItem) {
			set({
				active: tab
			});
		},
		setScope (val) {
			set({
				scope: val
			});
		},
		setServiceType(typeItem: ServiceTypeItem) {
			set({
				serviceType: typeItem
			});
		},
		setCurrentDate(val: number) {
			set({
				currentDate: val
			});
		},
		monthOrYear: MonthYearTabs[0].value,
		setMonthOrYear(k: MonthYearKey) {
			set({
				monthOrYear: k
			});
		}
	};
});

